package com.sakila.action;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginAction {
	
	@RequestMapping(value="/staff/login")
	public String loginDispatcherForStaff(@RequestParam(required=false)String error, Model model){
		if(error == null){
			return "staff/login";
		}
		
		switch (error) {
		case "error":
			model.addAttribute("error", "Invalid username and password!");
			break;
		case "deny":
			model.addAttribute("error", "Please login to continue processing.");
			break;
		case "update":
			model.addAttribute("error", "You have changed your password, please re-login.");
			break;
		}
		return "staff/login";
	}
	
	@RequestMapping(value="/member/login")
	public String loginDispatcherForMember(@RequestParam(required=false)String error, Model model){
		if(error == null){
			return "member/login";
		}
		
		switch (error) {
		case "error":
			model.addAttribute("error", "Invalid username and password!");
			break;
		case "deny":
			model.addAttribute("error", "Please login to continue processing.");
			break;
		}
		return "member/login";
	}
}
